/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

/*
 * TelaInicial.java
 *
 * Created on 01/06/2011, 16:03:32
 */

package pacote;

import Relatorios.ExcRepositorio;
import javax.swing.JOptionPane;
import net.sf.jasperreports.engine.JRException;
import net.sf.jasperreports.engine.JasperPrint;
import net.sf.jasperreports.view.JasperViewer;
import Relatorios.PrincipalClientes;
import Relatorios.PrincipalProdutos;
import Relatorios.RepositorioCliente;
import Relatorios.RepositorioProduto;
import javax.persistence.EntityManager;

/**
 *
 * @author David
 */
public class TelaInicial extends javax.swing.JFrame {

    private Admin adm;
    private EntityManager em;

    /** Creates new form TelaInicial */
    public TelaInicial(Admin admin, EntityManager exem) {
        initComponents();
        this.adm = admin;
        this.em = exem;
    }

    /** This method is called from within the constructor to
     * initialize the form.
     * WARNING: Do NOT modify this code. The content of this method is
     * always regenerated by the Form Editor.
     */
    @SuppressWarnings("unchecked")
    // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
    private void initComponents() {

        jMenuBar2 = new javax.swing.JMenuBar();
        jMenu3 = new javax.swing.JMenu();
        jMenu4 = new javax.swing.JMenu();
        jMenuBar1 = new javax.swing.JMenuBar();
        jMenu1 = new javax.swing.JMenu();
        ClienteCadastrar = new javax.swing.JMenuItem();
        jSeparator1 = new javax.swing.JPopupMenu.Separator();
        jMenuItem2 = new javax.swing.JMenuItem();
        jSeparator2 = new javax.swing.JPopupMenu.Separator();
        jMenuItem3 = new javax.swing.JMenuItem();
        jSeparator3 = new javax.swing.JPopupMenu.Separator();
        jMenuItem4 = new javax.swing.JMenuItem();
        mProdutos = new javax.swing.JMenu();
        mProdCad = new javax.swing.JMenuItem();
        jSeparator4 = new javax.swing.JPopupMenu.Separator();
        mProdEdit = new javax.swing.JMenuItem();
        jSeparator5 = new javax.swing.JPopupMenu.Separator();
        jSeparator6 = new javax.swing.JPopupMenu.Separator();
        mProdList = new javax.swing.JMenuItem();
        mProdDel = new javax.swing.JMenuItem();
        mCat = new javax.swing.JMenu();
        mVendas = new javax.swing.JMenu();
        mVendasCad = new javax.swing.JMenuItem();
        jSeparator7 = new javax.swing.JPopupMenu.Separator();
        mVendasDel = new javax.swing.JMenuItem();
        jSeparator9 = new javax.swing.JPopupMenu.Separator();
        mVendasList = new javax.swing.JMenuItem();
        mRel = new javax.swing.JMenu();
        mRelVendas = new javax.swing.JMenuItem();
        jSeparator13 = new javax.swing.JPopupMenu.Separator();
        mRelProd = new javax.swing.JMenuItem();
        mUser = new javax.swing.JMenu();
        jSeparator10 = new javax.swing.JPopupMenu.Separator();
        mUserCad = new javax.swing.JMenuItem();
        mUserEdit = new javax.swing.JMenuItem();
        jSeparator11 = new javax.swing.JPopupMenu.Separator();
        mUserDel = new javax.swing.JMenuItem();
        jSeparator12 = new javax.swing.JPopupMenu.Separator();
        mUserList = new javax.swing.JMenuItem();

        jMenu3.setText("File");
        jMenuBar2.add(jMenu3);

        jMenu4.setText("Edit");
        jMenuBar2.add(jMenu4);

        setDefaultCloseOperation(javax.swing.WindowConstants.EXIT_ON_CLOSE);
        setTitle("Sistema de Gerenciamento - eCom Fire");

        jMenu1.setText("Clientes");

        ClienteCadastrar.setAccelerator(javax.swing.KeyStroke.getKeyStroke(java.awt.event.KeyEvent.VK_A, java.awt.event.InputEvent.CTRL_MASK));
        ClienteCadastrar.setIcon(new javax.swing.ImageIcon(getClass().getResource("/imgs/cadastrar.png"))); // NOI18N
        ClienteCadastrar.setText("Cadastrar");
        ClienteCadastrar.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                ClienteCadastrarActionPerformed(evt);
            }
        });
        jMenu1.add(ClienteCadastrar);
        jMenu1.add(jSeparator1);

        jMenuItem2.setAccelerator(javax.swing.KeyStroke.getKeyStroke(java.awt.event.KeyEvent.VK_E, java.awt.event.InputEvent.CTRL_MASK));
        jMenuItem2.setIcon(new javax.swing.ImageIcon(getClass().getResource("/imgs/editar.png"))); // NOI18N
        jMenuItem2.setText("Editar");
        jMenuItem2.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jMenuItem2ActionPerformed(evt);
            }
        });
        jMenu1.add(jMenuItem2);
        jMenu1.add(jSeparator2);

        jMenuItem3.setAccelerator(javax.swing.KeyStroke.getKeyStroke(java.awt.event.KeyEvent.VK_D, java.awt.event.InputEvent.CTRL_MASK));
        jMenuItem3.setIcon(new javax.swing.ImageIcon(getClass().getResource("/imgs/deletar.png"))); // NOI18N
        jMenuItem3.setText("Deletar");
        jMenuItem3.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jMenuItem3ActionPerformed(evt);
            }
        });
        jMenu1.add(jMenuItem3);
        jMenu1.add(jSeparator3);

        jMenuItem4.setAccelerator(javax.swing.KeyStroke.getKeyStroke(java.awt.event.KeyEvent.VK_L, java.awt.event.InputEvent.CTRL_MASK));
        jMenuItem4.setIcon(new javax.swing.ImageIcon(getClass().getResource("/imgs/lista.png"))); // NOI18N
        jMenuItem4.setText("Listar");
        jMenuItem4.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jMenuItem4ActionPerformed(evt);
            }
        });
        jMenu1.add(jMenuItem4);

        jMenuBar1.add(jMenu1);

        mProdutos.setText("Produtos");

        mProdCad.setIcon(new javax.swing.ImageIcon(getClass().getResource("/imgs/cadastrar.png"))); // NOI18N
        mProdCad.setText("Cadastrar");
        mProdCad.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                mProdCadActionPerformed(evt);
            }
        });
        mProdutos.add(mProdCad);
        mProdutos.add(jSeparator4);

        mProdEdit.setAccelerator(javax.swing.KeyStroke.getKeyStroke(java.awt.event.KeyEvent.VK_E, java.awt.event.InputEvent.SHIFT_MASK));
        mProdEdit.setIcon(new javax.swing.ImageIcon(getClass().getResource("/imgs/editar.png"))); // NOI18N
        mProdEdit.setText("Editar");
        mProdEdit.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                mProdEditActionPerformed(evt);
            }
        });
        mProdutos.add(mProdEdit);
        mProdutos.add(jSeparator5);
        mProdutos.add(jSeparator6);

        mProdList.setAccelerator(javax.swing.KeyStroke.getKeyStroke(java.awt.event.KeyEvent.VK_L, java.awt.event.InputEvent.SHIFT_MASK));
        mProdList.setIcon(new javax.swing.ImageIcon(getClass().getResource("/imgs/lista.png"))); // NOI18N
        mProdList.setText("Listar");
        mProdList.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                mProdListActionPerformed(evt);
            }
        });
        mProdutos.add(mProdList);

        mProdDel.setAccelerator(javax.swing.KeyStroke.getKeyStroke(java.awt.event.KeyEvent.VK_D, java.awt.event.InputEvent.SHIFT_MASK));
        mProdDel.setIcon(new javax.swing.ImageIcon(getClass().getResource("/imgs/deletar.png"))); // NOI18N
        mProdDel.setText("Deletar");
        mProdDel.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                mProdDelActionPerformed(evt);
            }
        });
        mProdutos.add(mProdDel);

        jMenuBar1.add(mProdutos);

        mCat.setText("Categorias");
        mCat.addMouseListener(new java.awt.event.MouseAdapter() {
            public void mousePressed(java.awt.event.MouseEvent evt) {
                mCatMousePressed(evt);
            }
        });
        jMenuBar1.add(mCat);

        mVendas.setText("Vendas");

        mVendasCad.setAccelerator(javax.swing.KeyStroke.getKeyStroke(java.awt.event.KeyEvent.VK_C, java.awt.event.InputEvent.SHIFT_MASK | java.awt.event.InputEvent.CTRL_MASK));
        mVendasCad.setIcon(new javax.swing.ImageIcon(getClass().getResource("/imgs/cadastrar.png"))); // NOI18N
        mVendasCad.setText("Cadastrar");
        mVendasCad.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                mVendasCadActionPerformed(evt);
            }
        });
        mVendas.add(mVendasCad);
        mVendas.add(jSeparator7);

        mVendasDel.setAccelerator(javax.swing.KeyStroke.getKeyStroke(java.awt.event.KeyEvent.VK_D, java.awt.event.InputEvent.SHIFT_MASK | java.awt.event.InputEvent.CTRL_MASK));
        mVendasDel.setIcon(new javax.swing.ImageIcon(getClass().getResource("/imgs/deletar.png"))); // NOI18N
        mVendasDel.setText("Deletar");
        mVendasDel.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                mVendasDelActionPerformed(evt);
            }
        });
        mVendas.add(mVendasDel);
        mVendas.add(jSeparator9);

        mVendasList.setIcon(new javax.swing.ImageIcon(getClass().getResource("/imgs/lista.png"))); // NOI18N
        mVendasList.setText("Listar");
        mVendasList.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                mVendasListActionPerformed(evt);
            }
        });
        mVendas.add(mVendasList);

        jMenuBar1.add(mVendas);

        mRel.setText("Relatórios");

        mRelVendas.setAccelerator(javax.swing.KeyStroke.getKeyStroke(java.awt.event.KeyEvent.VK_R, java.awt.event.InputEvent.CTRL_MASK));
        mRelVendas.setIcon(new javax.swing.ImageIcon(getClass().getResource("/imgs/relatorio.png"))); // NOI18N
        mRelVendas.setText("Cliente");
        mRelVendas.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                mRelVendasActionPerformed(evt);
            }
        });
        mRel.add(mRelVendas);
        mRel.add(jSeparator13);

        mRelProd.setAccelerator(javax.swing.KeyStroke.getKeyStroke(java.awt.event.KeyEvent.VK_P, java.awt.event.InputEvent.CTRL_MASK));
        mRelProd.setIcon(new javax.swing.ImageIcon(getClass().getResource("/imgs/relatorio.png"))); // NOI18N
        mRelProd.setText("Produtos");
        mRelProd.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                mRelProdActionPerformed(evt);
            }
        });
        mRel.add(mRelProd);

        jMenuBar1.add(mRel);

        mUser.setText("Usuário do Sistema");
        mUser.add(jSeparator10);

        mUserCad.setAccelerator(javax.swing.KeyStroke.getKeyStroke(java.awt.event.KeyEvent.VK_C, java.awt.event.InputEvent.ALT_MASK | java.awt.event.InputEvent.CTRL_MASK));
        mUserCad.setIcon(new javax.swing.ImageIcon(getClass().getResource("/imgs/cadastrar.png"))); // NOI18N
        mUserCad.setText("Cadastrar");
        mUserCad.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                mUserCadActionPerformed(evt);
            }
        });
        mUser.add(mUserCad);

        mUserEdit.setAccelerator(javax.swing.KeyStroke.getKeyStroke(java.awt.event.KeyEvent.VK_E, java.awt.event.InputEvent.ALT_MASK | java.awt.event.InputEvent.CTRL_MASK));
        mUserEdit.setIcon(new javax.swing.ImageIcon(getClass().getResource("/imgs/editar.png"))); // NOI18N
        mUserEdit.setText("Editar");
        mUserEdit.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                mUserEditActionPerformed(evt);
            }
        });
        mUser.add(mUserEdit);
        mUser.add(jSeparator11);

        mUserDel.setAccelerator(javax.swing.KeyStroke.getKeyStroke(java.awt.event.KeyEvent.VK_D, java.awt.event.InputEvent.ALT_MASK | java.awt.event.InputEvent.CTRL_MASK));
        mUserDel.setIcon(new javax.swing.ImageIcon(getClass().getResource("/imgs/deletar.png"))); // NOI18N
        mUserDel.setText("Deletar");
        mUserDel.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                mUserDelActionPerformed(evt);
            }
        });
        mUser.add(mUserDel);
        mUser.add(jSeparator12);

        mUserList.setAccelerator(javax.swing.KeyStroke.getKeyStroke(java.awt.event.KeyEvent.VK_L, java.awt.event.InputEvent.ALT_MASK | java.awt.event.InputEvent.CTRL_MASK));
        mUserList.setIcon(new javax.swing.ImageIcon(getClass().getResource("/imgs/lista.png"))); // NOI18N
        mUserList.setText("Listar");
        mUserList.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                mUserListActionPerformed(evt);
            }
        });
        mUser.add(mUserList);

        jMenuBar1.add(mUser);

        setJMenuBar(jMenuBar1);

        javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane());
        getContentPane().setLayout(layout);
        layout.setHorizontalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGap(0, 821, Short.MAX_VALUE)
        );
        layout.setVerticalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGap(0, 450, Short.MAX_VALUE)
        );

        pack();
    }// </editor-fold>//GEN-END:initComponents

    private void ClienteCadastrarActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_ClienteCadastrarActionPerformed
       if (evt.getSource() == this.ClienteCadastrar){
            new ClienteCadastra(this.em).setVisible(true);  
       }

    }//GEN-LAST:event_ClienteCadastrarActionPerformed

    private void jMenuItem3ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jMenuItem3ActionPerformed
        if (evt.getSource() == this.jMenuItem3){
            new ClienteRemove(this.em).setVisible(true);
        }
    }//GEN-LAST:event_jMenuItem3ActionPerformed

    private void jMenuItem4ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jMenuItem4ActionPerformed
        if (evt.getSource() == this.jMenuItem4){
            new ClienteLista(this.em).setVisible(true);
        }
    }//GEN-LAST:event_jMenuItem4ActionPerformed

    private void jMenuItem2ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jMenuItem2ActionPerformed
        if (evt.getSource() == this.jMenuItem2){
            new ClienteAltera(this.em).setVisible(true);
        }
    }//GEN-LAST:event_jMenuItem2ActionPerformed

    private void mUserCadActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_mUserCadActionPerformed
       if (evt.getSource() == this.mUserCad){
            new UserSisCadastra(this.em).setVisible(true);
       }
    }//GEN-LAST:event_mUserCadActionPerformed

    private void mUserEditActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_mUserEditActionPerformed
        if (evt.getSource() == this.mUserEdit){
            new UserSisAltera(this.em).setVisible(true);
        }    // TODO add your handling code here:
    }//GEN-LAST:event_mUserEditActionPerformed

    private void mUserDelActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_mUserDelActionPerformed
        if (evt.getSource() == this.mUserDel){
            new UserSisRemove(this.em).setVisible(true);
        }        // TODO add your handling code here:
    }//GEN-LAST:event_mUserDelActionPerformed

    private void mUserListActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_mUserListActionPerformed
        if (evt.getSource() == this.mUserList){
            new UserSisLista(this.em).setVisible(true);
        }        // TODO add your handling code here:
    }//GEN-LAST:event_mUserListActionPerformed

    private void mProdDelActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_mProdDelActionPerformed
        if (evt.getSource() == this.mProdDel){
            new ProdRemove(this.em).setVisible(true);
        }          // TODO add your handling code here:
    }//GEN-LAST:event_mProdDelActionPerformed

    private void mProdListActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_mProdListActionPerformed
        if (evt.getSource() == this.mProdList){
            new ProdLista(this.em).setVisible(true);
        }            // TODO add your handling code here:
    }//GEN-LAST:event_mProdListActionPerformed

    private void mProdCadActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_mProdCadActionPerformed
        if (evt.getSource() == this.mProdCad){
            new ProdCadastra(this.em).setVisible(true);
        }         // TODO add your handling code here:
    }//GEN-LAST:event_mProdCadActionPerformed

    private void mProdEditActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_mProdEditActionPerformed
        // TODO add your handling code here:
        if(evt.getSource() == this.mProdEdit){
            new ProdAltera(this.em).setVisible(true);
        }
    }//GEN-LAST:event_mProdEditActionPerformed

    private void mCatMousePressed(java.awt.event.MouseEvent evt) {//GEN-FIRST:event_mCatMousePressed
        if (evt.getSource() == this.mCat){
            new CategoriasEdit(this.em).setVisible(true);
        }
    }//GEN-LAST:event_mCatMousePressed

    private void mVendasListActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_mVendasListActionPerformed
        // TODO add your handling code here:
        if(evt.getSource() == this.mVendasList){
            new VendasLista(this.em).setVisible(true);
        }
    }//GEN-LAST:event_mVendasListActionPerformed

    private void mVendasDelActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_mVendasDelActionPerformed
        // TODO add your handling code here:
        if(evt.getSource() == this.mVendasDel){
            new VendasRemove(this.em).setVisible(true);
        }
    }//GEN-LAST:event_mVendasDelActionPerformed

    private void mVendasCadActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_mVendasCadActionPerformed
        // TODO add your handling code here:
        if(evt.getSource() == this.mVendasCad){
            new VendasCadastra(this.em).setVisible(true);
        }
    }//GEN-LAST:event_mVendasCadActionPerformed

    private void mRelVendasActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_mRelVendasActionPerformed
        if (evt.getSource() == this.mRelVendas){
                RepositorioCliente rep = new RepositorioCliente();
		JasperPrint relat;

                try {
			relat = rep.gerar();
			JasperViewer.viewReport(relat, false);
		} catch (ExcRepositorio e) {
			JOptionPane.showMessageDialog(null, "Erro: " + e.getMessage());
		}

            //PrincipalClientes cli = new PrincipalClientes();
        }
    }//GEN-LAST:event_mRelVendasActionPerformed

    private void mRelProdActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_mRelProdActionPerformed
        if (evt.getSource() == this.mRelProd){
		RepositorioProduto rep = new RepositorioProduto();
		JasperPrint relat;

                try {
			relat = rep.gerar();
			JasperViewer.viewReport(relat, false);
		} catch (ExcRepositorio e) {
			JOptionPane.showMessageDialog(null, "Erro: " + e.getMessage());
		}
        }
    }//GEN-LAST:event_mRelProdActionPerformed

    /**
    * @param args the command line arguments
    */


    // Variables declaration - do not modify//GEN-BEGIN:variables
    private javax.swing.JMenuItem ClienteCadastrar;
    private javax.swing.JMenu jMenu1;
    private javax.swing.JMenu jMenu3;
    private javax.swing.JMenu jMenu4;
    private javax.swing.JMenuBar jMenuBar1;
    private javax.swing.JMenuBar jMenuBar2;
    private javax.swing.JMenuItem jMenuItem2;
    private javax.swing.JMenuItem jMenuItem3;
    private javax.swing.JMenuItem jMenuItem4;
    private javax.swing.JPopupMenu.Separator jSeparator1;
    private javax.swing.JPopupMenu.Separator jSeparator10;
    private javax.swing.JPopupMenu.Separator jSeparator11;
    private javax.swing.JPopupMenu.Separator jSeparator12;
    private javax.swing.JPopupMenu.Separator jSeparator13;
    private javax.swing.JPopupMenu.Separator jSeparator2;
    private javax.swing.JPopupMenu.Separator jSeparator3;
    private javax.swing.JPopupMenu.Separator jSeparator4;
    private javax.swing.JPopupMenu.Separator jSeparator5;
    private javax.swing.JPopupMenu.Separator jSeparator6;
    private javax.swing.JPopupMenu.Separator jSeparator7;
    private javax.swing.JPopupMenu.Separator jSeparator9;
    private javax.swing.JMenu mCat;
    private javax.swing.JMenuItem mProdCad;
    private javax.swing.JMenuItem mProdDel;
    private javax.swing.JMenuItem mProdEdit;
    private javax.swing.JMenuItem mProdList;
    private javax.swing.JMenu mProdutos;
    private javax.swing.JMenu mRel;
    private javax.swing.JMenuItem mRelProd;
    private javax.swing.JMenuItem mRelVendas;
    private javax.swing.JMenu mUser;
    private javax.swing.JMenuItem mUserCad;
    private javax.swing.JMenuItem mUserDel;
    private javax.swing.JMenuItem mUserEdit;
    private javax.swing.JMenuItem mUserList;
    private javax.swing.JMenu mVendas;
    private javax.swing.JMenuItem mVendasCad;
    private javax.swing.JMenuItem mVendasDel;
    private javax.swing.JMenuItem mVendasList;
    // End of variables declaration//GEN-END:variables

}
